﻿using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BaseUi.Views.PlcView
{
    /// <summary>
    /// ElectricView.xaml 的交互逻辑电推杆页面
    /// </summary>
    public partial class ElectricView : UserControlBase
    {
        private informationData viewformModel = new informationData();
        public SolidColorBrush RedColor = new SolidColorBrush(Color.FromRgb(255, 69, 0));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220));
        public ElectricView()
        {
            InitializeComponent(); 
            DataContext = viewformModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            Task electric = new Task(() =>
            {
                while (true)
                {
                    getinform();
                    Thread.Sleep(200);
                }
            });
            electric.Start();
        }

        private void getinform()
        {
            var ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 22).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect1g1 = BoroColor;
                viewformModel.ContElect1g1 = " ";
                viewformModel.Elect1g3 = BoroColor;
                viewformModel.ContElect1g3 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect1g1 = GreenColor;
                    viewformModel.ContElect1g1 = "ON";
                    viewformModel.Elect1g3 = GreenColor;
                    viewformModel.ContElect1g3 = "ON";
                }
                else
                {
                    viewformModel.Elect1g1 = RedColor;
                    viewformModel.ContElect1g1 = "OFF";
                    viewformModel.Elect1g3 = RedColor;
                    viewformModel.ContElect1g3 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 23).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect1g2 = BoroColor;
                viewformModel.ContElect1g2 = " ";
                viewformModel.Elect1g4 = BoroColor;
                viewformModel.ContElect1g4 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect1g2 = GreenColor;
                    viewformModel.ContElect1g2 = "ON";
                    viewformModel.Elect1g4 = GreenColor;
                    viewformModel.ContElect1g4 = "ON";
                }
                else
                {
                    viewformModel.Elect1g2 = RedColor;
                    viewformModel.ContElect1g2 = "OFF";
                    viewformModel.Elect1g4 = RedColor;
                    viewformModel.ContElect1g4 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 24).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect1g5 = BoroColor;
                viewformModel.ContElect1g5 = " ";
                viewformModel.Elect1g7 = BoroColor;
                viewformModel.ContElect1g7 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect1g5 = GreenColor;
                    viewformModel.ContElect1g5 = "ON";
                    viewformModel.Elect1g7 = GreenColor;
                    viewformModel.ContElect1g7 = "ON";
                }
                else
                {
                    viewformModel.Elect1g5 = RedColor;
                    viewformModel.ContElect1g5 = "OFF";
                    viewformModel.Elect1g7 = RedColor;
                    viewformModel.ContElect1g7 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 25).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect1g6 = BoroColor;
                viewformModel.ContElect1g6 = " ";
                viewformModel.Elect1g8 = BoroColor;
                viewformModel.ContElect1g8 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect1g6 = GreenColor;
                    viewformModel.ContElect1g6 = "ON";
                    viewformModel.Elect1g8 = GreenColor;
                    viewformModel.ContElect1g8 = "ON";
                }
                else
                {
                    viewformModel.Elect1g6 = RedColor;
                    viewformModel.ContElect1g6 = "OFF";
                    viewformModel.Elect1g8 = RedColor;
                    viewformModel.ContElect1g8 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 26).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect2g1 = BoroColor;
                viewformModel.ContElect2g1 = " ";
                viewformModel.Elect2g3 = BoroColor;
                viewformModel.ContElect2g3 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect2g1 = GreenColor;
                    viewformModel.ContElect2g1 = "ON";
                    viewformModel.Elect2g3 = GreenColor;
                    viewformModel.ContElect2g3 = "ON";
                }
                else
                {
                    viewformModel.Elect2g1 = RedColor;
                    viewformModel.ContElect2g1 = "OFF";
                    viewformModel.Elect2g3 = RedColor;
                    viewformModel.ContElect2g3 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 27).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect2g2 = BoroColor;
                viewformModel.ContElect2g2 = " ";
                viewformModel.Elect2g4 = BoroColor;
                viewformModel.ContElect2g4 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect2g2 = GreenColor;
                    viewformModel.ContElect2g2 = "ON";
                    viewformModel.Elect2g4 = GreenColor;
                    viewformModel.ContElect2g4 = "ON";
                }
                else
                {
                    viewformModel.Elect2g2 = RedColor;
                    viewformModel.ContElect2g2 = "OFF";
                    viewformModel.Elect2g4 = RedColor;
                    viewformModel.ContElect2g4 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 28).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect2g5 = BoroColor;
                viewformModel.ContElect2g5 = " ";
                viewformModel.Elect2g7 = BoroColor;
                viewformModel.ContElect2g7 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect2g5 = GreenColor;
                    viewformModel.ContElect2g5 = "ON";
                    viewformModel.Elect2g7 = GreenColor;
                    viewformModel.ContElect2g7 = "ON";
                }
                else
                {
                    viewformModel.Elect2g5 = RedColor;
                    viewformModel.ContElect2g5 = "OFF";
                    viewformModel.Elect2g7 = RedColor;
                    viewformModel.ContElect2g7 = "OFF";
                }
            }
            ioi1g1 = LocalStatic.Plc.Read<bool>((64512 + 29).ToString());
            if (ioi1g1.IsSucceed == false)
            {
                viewformModel.Elect2g6 = BoroColor;
                viewformModel.ContElect2g6 = " ";
                viewformModel.Elect2g8 = BoroColor;
                viewformModel.ContElect2g8 = " ";
            }
            else
            {
                if (ioi1g1.Value)
                {
                    viewformModel.Elect2g6 = GreenColor;
                    viewformModel.ContElect2g6 = "ON";
                    viewformModel.Elect2g8 = GreenColor;
                    viewformModel.ContElect2g8 = "ON";
                }
                else
                {
                    viewformModel.Elect2g6 = RedColor;
                    viewformModel.ContElect2g6 = "OFF";
                    viewformModel.Elect2g8 = RedColor;
                    viewformModel.ContElect2g8 = "OFF";
                }
            }
        }

        

        private void outinformButton_Click1g1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("91", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("92", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g3(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("93", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g4(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("94", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g5(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("95", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g6(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("96", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g7(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("97", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click1g8(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("98", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("99", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("100", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g3(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("101", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g4(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("102", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g5(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("103", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g6(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("104", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g7(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("105", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void outinformButton_Click2g8(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("106", (sender as Button).Content == "OFF");
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
    }
}
